<template>
  <div class="classA">
    <el-container style="height: 500px; border: 1px solid #eee">
      <el-aside width="200px" style="background-color: rgb(238, 241, 246)">
        <el-menu
            @select="handleSelect">

          <el-submenu v-for="category in level1" :key="category.id" :index="category.id">
            <template slot="title"><i class="el-icon-message"></i>{{ category.name }}</template>
            <el-menu-item-group>
              <el-menu-item v-for="cate in category.children" :key="cate.id" :index="cate.id">
                {{ cate.name }}
              </el-menu-item>

            </el-menu-item-group>
          </el-submenu>
        </el-menu>
      </el-aside>

      <el-container>
        <el-header style="text-align: right; font-size: 12px">
          <el-dropdown>
            <i class="el-icon-setting" style="margin-right: 15px"></i>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item>查看</el-dropdown-item>
              <el-dropdown-item>新增</el-dropdown-item>
              <el-dropdown-item>删除</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
          <span>王小虎</span>
        </el-header>

        <el-main>
          <el-table :data="tableData"
                    @row-click="handleProblem">
            <el-table-column label="#" align="center" width="40">
              <template slot-scope="scope">
                <i :class="STATUS_SET[scope.row.status]"
                   :style="STATUS_COLOR_SET[scope.row.status]"></i>
              </template>
            </el-table-column>
            <el-table-column prop="problemId" label="题目id">
            </el-table-column>
            <el-table-column prop="title" label="标题">
            </el-table-column>
            <el-table-column prop="accept" label="通过">
            </el-table-column>
            <el-table-column prop="submit" label="提交">
            </el-table-column>
          </el-table>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import {allCategory, deleteCategory, saveCategory} from "@/network/category";
import {Confirm} from '@/assets/js/confirm'
import {Validator} from "@/assets/js/validator";

export default {
  name: "category",
  mounted() {
    this.all()
  },
  data() {

    return {
      formLabelWidth: '120px',
      list: [],
      level1: [],
      level2: [],
      currentLevel1: null,
    }
  },
  methods: {
    all() {
      let _this = this;
      allCategory().then(res => {
        _this.list = res.data
        _this.level1 = [];
        _this.level2 = [];
        _this.currentLevel1 = null;

        for (let i = 0; i < _this.list.length; i++) {
          let c = _this.list[i];
          if (c.parent === '00000000') {
            _this.level1.push(c);
            c.children = [];
            for (let j = 0; j < _this.list.length; j++) {
              if (_this.list[j].parent == c.id) {
                c.children.push(_this.list[j]);
              }
            }
          }
        }
      })
    },
    level1Click(row) {
      let _this = this;
      _this.currentLevel1 = row
      _this.$refs.level1Table.setCurrentRow(row);
      _this.level2 = row.children;
    }
  }
}
</script>

<style scoped>
.category-left {
  width: 40%;
  margin: auto;
}

.category-right {
  margin: auto;
  width: 40%;
}
</style>
